package com.getpebble.android.jskit;

import com.getpebble.android.jskit.webapps.WebappRunHost;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class NoUiAppsList {
    private static NoUiAppsList sInstance;
    List<WebappRunHost> mNoUiAppsList = new ArrayList();
    Lock mNoUiAppsListLock = new ReentrantLock();

    public interface IWebappRunHostListOperator {
        Object operatingUnderLock(List<WebappRunHost> list, Object... objArr);
    }

    private NoUiAppsList() {
    }

    public static NoUiAppsList getInstance() {
        if (sInstance == null) {
            sInstance = new NoUiAppsList();
        }
        return sInstance;
    }

    public void noUiAppsListLockedAccess(IWebappRunHostListOperator callback, Object... optContextDataVararg) {
        if (callback != null) {
            this.mNoUiAppsListLock.lock();
            callback.operatingUnderLock(this.mNoUiAppsList, optContextDataVararg);
            this.mNoUiAppsListLock.unlock();
        }
    }

    public Object noUiAppsListLockedAccessWithResult(IWebappRunHostListOperator callback, Object... optContextDataVararg) {
        if (callback == null) {
            return null;
        }
        this.mNoUiAppsListLock.lock();
        Object result = callback.operatingUnderLock(this.mNoUiAppsList, optContextDataVararg);
        this.mNoUiAppsListLock.unlock();
        return result;
    }
}
